
package Navigation;

import java.util.Hashtable;

class CrossingCollectionImpl implements ICollection{

	private Hashtable<Integer,CrossingTopologyObjectImpl> crossings;
	private ICollection coordinateCollection;
	
    public CrossingCollectionImpl(ICollection coordinateCollection){
    	this.coordinateCollection = coordinateCollection;
    	crossings = new Hashtable<Integer, CrossingTopologyObjectImpl>();
    }

    public void add(ITopologyObject iTopologyObject) {
        if(iTopologyObject.getClass() == CrossingTopologyObjectImpl.class){
        	CrossingTopologyObjectImpl crossing = (CrossingTopologyObjectImpl)iTopologyObject;
        	addCrossing(crossing);
        	ITopologyObject coordinate = crossing.getCoordinate();
        	coordinateCollection.add(coordinate);
        }
    }

	public ITopologyObject getTopologyObject(Object key) {
		if(key.getClass() == Integer.class){
			CrossingTopologyObjectImpl crossing = (CrossingTopologyObjectImpl)crossings.get(key);
			return crossing;
		}else{
			return null;
		}
	}

    private void addCrossing(CrossingTopologyObjectImpl crossing){
    	crossings.put(crossing.getID(), crossing);
    }

}
